<link rel="stylesheet" href="themes/editor/default.css" />
<script charset="utf-8" type="text/javascript" src="js/editor/editor-min.js"></script>
<script charset="utf-8"  type="text/javascript" src="js/editor/editor_zh_CN.js"></script>
<form id="addSurgeryfm" method="post" novalidate>
<div class="ftitle">添加手术记录</div>
	<div id="add_Surgery_1" next="#add_Surgery_2">
        	<div class="fitem">
               	<label>手术名称:</label>
                <input id="addSurgery_title" name="addSurgery_title" style="width:148px" class="easyui-validatebox" required="true">
            </div>
        	<div class="fitem">
                	<label>手术合同:</label>
                 <select name="addSurgery_Contract" id="addSurgery_Contract" style="width:150px"  class="easyui-validatebox" required="true">
    				</select>
            </div>
        	<div class="fitem">
                	<label>手术时间:</label>
                    <select name="addSurgery_time" style="width:150px"  class="easyui-datetimebox" required>
    				</select>
            </div>
            <div class="fitem">
                	<label>手术项目:</label>
                <input id="addSurgery_items" name="addSurgery_items" style="width:250px">
            </div>
            <div class="tabLink">
			<ul>
				<li><a href="javascript:void(0)" onclick="javascript:addSurgeryJs.nextStep('#add_Surgery_1')">下一步</a></li>
			</ul>
			</div>
            
    </div>
    <div id="add_Surgery_2" style="display:none" pre="#add_Surgery_1" next="#add_Surgery_3">
            <div class="fitem">
                <label>主刀医生:</label>
                <input id="addSurgery_doctor" name="addSurgery_doctor" style="width:150px" class="easyui-validatebox" required="true">
            </div>
        	<div class="fitem">
                	<label>其他医生护士:</label>
                    <input name="addSurgery_otherOperator" style="width:250px"/>
            </div>
            <div class="fitem">
                	<label>麻醉医生:</label>
                <input id="addSurgery_mazuidoctor" name="addSurgery_mazuidoctor" style="width:150px">
            </div>
            <div class="fitem">
                <label>麻醉方式:</label>
				<select name="addSurgery_fangshi" style="width:150px">
					<option value="全麻">全麻</option>
					<option value="局麻">局麻</option>
					<option value="静脉麻醉">静脉麻醉</option>
    			</select>
            </div>
            <div class="tabLink">
			<ul>
				<li><a href="javascript:void(0)" onclick="javascript:addSurgeryJs.preStep('#add_Surgery_2')">上一步</a></li>
				<li><a href="javascript:void(0)" onclick="javascript:addSurgeryJs.nextStep('#add_Surgery_2')">下一步</a></li>
			</ul>
			</div>
			
     </div>   
     <div id="add_Surgery_3" style="display:none" pre="#add_Surgery_2" next="#add_Surgery_4">    
            <div class="fitem">
                <label><b>术前分析:</b></label>
                <br/><br/>
                <textarea style="width:90%;height:100px" name="addSurgery_analysis"></textarea>
            </div>  
            <div class="fitem">
                <label><b>手术设计:</b></label>
                <br/><br/>
                <textarea style="width:90%;height:100px" name="addSurgery_Design"></textarea>
            </div>   
            <div class="tabLink">
			<ul>
				<li><a href="javascript:void(0)" onclick="javascript:addSurgeryJs.preStep('#add_Surgery_3')">上一步</a></li>
				<li><a href="javascript:void(0)" onclick="javascript:addSurgeryJs.nextStep('#add_Surgery_3')">下一步</a></li>
			</ul>
			</div>   
     </div>
	<div id="add_Surgery_4" style="display:none" pre="#add_Surgery_3">    
            <div class="fitem">
                <label><b>手术过程描述:</b></label>
                <br/><br/>
                <textarea style="width:90%;height:100px" name="addSurgery_Process"></textarea>
            </div>   
            <div class="tabLink">
			<ul>
				<li><a href="javascript:void(0)" onclick="javascript:addSurgeryJs.preStep('#add_Surgery_4')">上一步</a></li>
				<li><a href="javascript:void(0)" onclick="javascript:addSurgeryJs.saveSurgery()">添加</a></li>
			</ul>
			</div>  
     </div>                          
        </form>
    
<script type="text/javascript">
(function( addSurgeryJs, $, undefined ) {

	var start = 0;
	var addSurgery_analysis = null;
	var addSurgery_Design = null;
	var addSurgery_Process = null;
	addSurgeryJs.init = function ()
	{	
		addSurgery_analysis = KindEditor.create('textarea[name="addSurgery_analysis"]', {
			resizeType : 1,
			allowPreviewEmoticons : true,
			allowImageUpload : false,
			basePath :"js/editor/",
			themesPath : "themes/editor/",
			themeType : 'default',
			items : [
				'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
				'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
				'insertunorderedlist', '|', 'emoticons', 'image', 'link']
		});
		addSurgery_Design = KindEditor.create('textarea[name="addSurgery_Design"]', {
			resizeType : 1,
			allowPreviewEmoticons : true,
			allowImageUpload : false,
			basePath :"js/editor/",
			themesPath : "themes/editor/",
			themeType : 'default',
			items : [
				'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
				'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
				'insertunorderedlist', '|', 'emoticons', 'image', 'link']
		});
		addSurgery_Process = KindEditor.create('textarea[name="addSurgery_Process"]', {
			resizeType : 1,
			allowImageUpload : true,
			basePath :"js/editor/",
			themesPath : "themes/editor/",
			themeType : 'default',
			uploadJson : 'file/upload',
			filePostName : "cfile",
			allowMediaUpload : true,
			extraFileUploadParams : {
                type : 'consult'
        		},
			items : [
				'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
				'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
				'insertunorderedlist', '|', 'emoticons', 'image', 'link']
		});
		$('#addSurgery_Contract').combogrid({
			    panelWidth:650,
			    panelHeight:250,
			    idField:'id',
			    textField:'sequence',
			    url:null,
			    columns:[[
							{title:'客户',field:'customerName',width:150},
			             	{title:'手术时间',field:'time',width:120,sortable:true},
			             	{title:'编号',field:'sequence',width:120,sortable:true},
			             	{title:'创建时间',field:'createTime',width:150,sortable:true},
			    ]],
			    pagination:true,
			    pageSize:5,
				pageList:[5],
		});

		
		var grid = $('#addSurgery_Contract').combogrid('grid');
		
		$(grid).datagrid('getPager').pagination({   
		    displayMsg:'当前显示从 [{from}] 到 [{to}] 共[{total}]条记录',   
		    onSelectPage : function(pPageIndex, pPageSize) {   
		    	
		        var gridOpts = $(grid).datagrid('options');   
		        gridOpts.pageNumber = pPageIndex;   
		        gridOpts.pageSize = pPageSize;     

		        start = (pPageIndex -1)*pPageSize;
		        postSearch();
		    },
		    onChangePageSize : function(pageSize){
		    	countPerPage = pageSize;
		    }
		});

		//loadData("dispatch/customer/opportunity/all?start=0&size=5",loadCAData);
		//loadData("dispatch/manage/item/all",loadItemsResult);
		//loadData("dispatch/manage/consultLevel/all",loadConsultLevel);
		//loadData("dispatch/manage/consultway/all",loadConsultWay);
		//loadData("dispatch/manage/employee/simpleAll",loadEmployeeResult);
		workbenchJs.loadData("dispatch/customer/contract/all",addSurgeryJs.loadCAData,"查看手术合同");
	};
	addSurgeryJs.loadCAData = function(result){
    	var res = result.result;
        if(res == "SUCCESS")
        {
        	var payload = jQuery.parseJSON(result.payload.value);
        	var grid = $('#addSurgery_Contract').combogrid('grid');
    		$(grid).datagrid("loaded");
        	$(grid).datagrid('loadData',payload);
        }else if(res == "COMPONENT_ERROR")
        {
        	$.messager.alert("Error",result.payload.value);
        }else
        {
        	$.messager.alert("Error",result.result);
        }
	};

	addSurgeryJs.nextStep = function (id){
		if($('#addConsultfm').form('validate'))
		{
			$(id).hide();
			var nextId = $(id).attr('next');
			$(nextId).show();
		}
	};
	addSurgeryJs.preStep = function (id){
		$(id).hide();
		var preId = $(id).attr('pre');
		$(preId).show();
	};
	
	addSurgeryJs.saveSurgery = function (){
		
		var surgery = {};
		surgery.contract = parseInt($("#addSurgeryfm input[name='addSurgery_Contract']").val());
		surgery.surgeryTime = $("#addSurgeryfm input[name='addSurgery_time']").val();
		surgery.title = $("#addSurgeryfm input[name='addSurgery_title']").val();
		surgery.items = $("#addSurgeryfm input[name='addSurgery_items']").val();
		surgery.doctor = $("#addSurgeryfm input[name='addSurgery_doctor']").val();
		surgery.otherOperator = $("#addSurgeryfm input[name='addSurgery_otherOperator']").val();
		surgery.mazuishi = $("#addSurgeryfm input[name='addSurgery_mazuidoctor']").val();
		surgery.mazuifangshi = $("#addSurgeryfm select[name='addSurgery_fangshi']").val();
		surgery.preoperaive = addSurgery_analysis.html();

		surgery.surgeryDesign = addSurgery_Design.html();
		surgery.surgeryProcess = addSurgery_Process.html();
		
    	
    	var str = $.toJSON(surgery);
    	str = 'parameters='+str;
    	if($('#addSurgeryfm').form('validate'))
    	{
    		$.ajax({
                type: "post",
                url: "dispatch/customer/surgeryRecord/add",
                dataType:"json",
                data: str,
                cache: false,
                success: function (result) {
                	var res = result.result;
                    if(res == "SUCCESS")
                    {
                    	$.messager.alert('Success','添加成功','info',function(){
                            workbenchJs.open1('component/customer/surgeryRecord.html',this);
                        });
                    }else if(res == "COMPONENT_ERROR")
                    {
                    	$.messager.alert("Error",result.payload.value);
                    }else
                    {
                    	$.messager.alert("Error",result.result);
                    }
                    
                }
                
            });
    	}
    };

	addSurgeryJs.clearSearch = function()
	{
		countPerPage = 5;
		start = 0;
		postSearch();
	}
	function postSearch()
	{
		var str = "";
		str = appendURL(str,'start='+start+'&size=5');
		$.ajax({
            type: "post",
            url: "dispatch/customer/contract/all",
            dataType:"json",
            data: str,
            cache: false,
            success: function (result) {
            	
            	loadCAData(result);
            }
		});
	}
	function appendURL(url,str1)
	{
		if(typeof(str1) == 'undefined')return url;
		if(url == "" || typeof(url) == 'undefined')url = str1;
		else url+="&"+str1;

		return url;
	}
	
	addSurgeryJs.ajaxFileUpload = function(){
        $.ajaxFileUpload(
        {
         	url:'file/upload',
        	secureuri:false,
         	fileElementId:'cfile',
        	dataType: 'json',
         	success: function (data, status)
        	{   
         		$.messager.alert("Success",data.result);
         	},
         	error: function (data, status, e)
       	 	{
         			alert(e);
         		
         		//$('#uploadResult').innerText = data;
//         		$.messager.alert("Error",data.result);
         	}
     	})
       }
}( window.addSurgeryJs = window.addSurgeryJs || {}, jQuery ));

$(function(){
	addSurgeryJs.init();
});
	</script>
    <style type="text/css">
        
    </style>